package com.fieldchain.ex.fa100.ui.personal.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.access.Constant;
import com.fieldchain.ex.fa100.base.MyBaseActivity;
import com.fieldchain.ex.fa100.bean.BankChoseBean;
import com.fieldchain.ex.fa100.inter.StringCallBack;
import com.fieldchain.ex.fa100.ui.personal.adapter.BankChoseAdapter;
import java.util.ArrayList;
import java.util.List;
import com.fieldchain.ex.fa100.utils.net.access.HttpRequest;
import com.fieldchain.ex.fa100.utils.net.modle.ListRequest;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/13
 */
public class BankChoseActivity extends MyBaseActivity {
    private RelativeLayout reaBack;
    private TextView tvCenter;
    private RecyclerView rv;


    private BankChoseAdapter adapter;
    private List<BankChoseBean> list = new ArrayList<>();

    private String name = "";

    @Override
    public void findView() {
        reaBack = findViewById(R.id.rea_back);
        tvCenter = findViewById(R.id.tv_center);
        rv = findViewById(R.id.rv);
    }

    @Override
    public void setValue() {
        reaBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tvCenter.setText("添加银行卡");
        name = getIntent().getStringExtra("name") + "";
        adapter = new BankChoseAdapter(mContext, new StringCallBack() {
            @Override
            public void message(String msg) {
                Intent intent = new Intent();
                intent.putExtra("name", msg);
                setResult(1010, intent);
                finish();
            }
        });
        if (name.length() > 0) {
            adapter.setCheckName(name);
        }
        rv.setLayoutManager(new LinearLayoutManager(mContext));
        rv.setAdapter(adapter);
        getData();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (name.length() > 0) {
            adapter.setCheckName(name);
        }
    }

    @Override
    public int getLayout() {
        return R.layout.activity_bankchose;
    }

    public void getData() {
        HttpRequest.getInstance().getRequest(Constant.bankchose, new ListRequest<BankChoseBean>() {
            @Override
            public void onSucess(List<BankChoseBean> l, int code, String msg) {
                list.clear();
                list.addAll(l);
                adapter.setData(list);
            }

            @Override
            public void onFaild(Exception e) {

            }
        });
    }
}
